package niit.game;

import java.util.Vector;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.util.Log;

public class MyPlane {
	static Vector<Bullet> bullets = null;
	static int health, life;
	static Bitmap plan, bullet;
	static GameView gameView;
	Bullet bullet2;
	static GameControls control;
	static int CurrentScore;
	static int CurrentRockKet;
	static boolean gameover;
	static Point PlanePoint = new Point(Main.SCREENWIDTH / 3,
			Main.SCREENHEIGHT / 3);

	public MyPlane(GameView gameView, GameControls control, Bitmap plan) {
		this.gameView = gameView;
		this.control = control;
		this.plan = plan;
		this.bullets = new Vector<Bullet>();
		this.bullet = BitmapFactory.decodeResource(gameView.getResources(),
				R.drawable.bullet1);
	}

	public static void newGame() {
		health = 30;
		life = 3;
		bullets = new Vector<Bullet>();
		PlanePoint = new Point(Main.SCREENWIDTH / 3, Main.SCREENHEIGHT / 3 * 2);

	}

	public static void shoot() {
		Log.d("Chay", "Goi shoot()");
		bullets.add(new Bullet(gameView, bullet, PlanePoint.x
				+ MyPlane.plan.getWidth() / 2 - bullet.getWidth() / 2,
				PlanePoint.y, 0, -(18 * Main.SCREENHEIGHT / 600), 1, 1));
//		bullets.add(new Bullet(gameView, bullet, PlanePoint.x
//				+ MyPlane.plan.getWidth() / 2 - bullet.getWidth() / 2,
//				PlanePoint.y, 2, 2, 1, 2));
//		bullets.add(new Bullet(gameView, bullet, PlanePoint.x
//				+ MyPlane.plan.getWidth() / 2 - bullet.getWidth() / 2,
//				PlanePoint.y, 2, 2, 1, 3));
	}

	public static boolean isCollision(Point spr1, int x, int y, Bitmap bmp) {
		return Math.sqrt(Math.pow(
				spr1.x - x + plan.getWidth() / 2 - bmp.getWidth() / 2, 2)
				+ Math.pow(spr1.y - y + plan.getHeight() / 2 - bmp.getHeight()
						/ 2, 2)) < plan.getHeight() / 2 + bmp.getHeight() / 2
				- 10;
	}

	public static void EneVsPlan(GameView gv) {
		if (gameView.enemy != null) {
			for (int i = 0; i < gameView.enemy.size(); i++) {

				if (isCollision(MyPlane.PlanePoint, gameView.enemy.get(i).x,
						gameView.enemy.get(i).y, gameView.enemy.get(i).enemyBit)) {
					MyPlane.health -= 2;
					if (MyPlane.health < 0) {
						life--;
						health=30;

						if (life < 0) {
							gameover = true;
						}
					}
					gameView.enemy.remove(i);
					// gameView.temps.add(new Temp(gv.temps, gv, Enemy.x,
					// Enemy.y,(Bitmap)BitmapFactory.decodeResource(gv.getResources(),
					// R.drawable.paper_flower)));
					break;

				}
			}
		}
	}

}
